/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


var XmppClient = Class.create({
   serverName: null,
   wsUrl: null,
   socket: null,
   initialize: function(_wsUrl, _serverName) {
        this.serverName = _serverName;
        this.wsUrl = _wsUrl;
   },
   onopen: function() {
    //@TODO
   },
   onclose: function() {
    //@TODO
   },
   onpresence: function() {
    //@TODO
   },
   onauthenticated: function() {
    //TODO
   },
   onerror: function() {
    //TODO
   },
   onmessage: function() {
    //@TODO
   },
   connect: function() {
       try {
            this.socket = new XmppWebSocket(this.wsUrl);
            socket.observe("XmppWebSocket::open", this.onopen());
            socket.observe("XmppWebSocket::close", this.onclose());
            socket.observe("XmppWebSocket::error", this.onerror());
            socket.observe("XmppWebSocket::message", this.onmessage());
       }
       catch(err) {
           console.log("XmppClient::ERROR::" + err);
       }
   },
   setStatus: function() {
    //TODO
   },
   disconnect: function() {
    //TODO
   },
   authenticate: function() {
    //TODO
   },
   bind: function() {
    //TODO
   },
   sendMessage: function(jid, msg) {
		var message = jabberIt("message", {
			"to" : jid,
			"type" : "chat",
			"xml:lang" : "en"
		}).c(jabberIt("body").val(msg));
		this._socket.send(message.toString());
   },
   getRoster: function() {
    //TODO
   },
   initConnection: function(xmppClient) {
		var msg = "";
		msg += "<?xml version='1.0'?>";
		msg += _constructStartOfStream(xmppClient.serverName);
		msg.socket.send(msg);
   },
   constructStartOfStream: function(hostname) {
        frame = "<stream:stream";
        frame += " to='" + hostname;
        frame += "' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>";
        return frame;
   },
   jabberIt: function() {
    //TODO
   }
});